//
//  SISSContractCheckLabelCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/25.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSContractCheckLabelCell.h"

@interface SISSContractCheckLabelCell ()
/// checkOneButton
@property (weak, nonatomic) UIButton *checkOneButton;
/// checkTwoButton
@property (weak, nonatomic) UIButton *checkTwoButton;
/// checkThreeButton
@property (weak, nonatomic) UIButton *checkThreeButton;
/// Label
@property (weak, nonatomic) UILabel *onelabel;
@property (weak, nonatomic) UILabel *twolabel;
@property (weak, nonatomic) UILabel *threelabel;
/* bottomLine */
@property (weak, nonatomic) UIView *bottomLine;

@property (weak, nonatomic) UIButton *checkedButton;

@end
@implementation SISSContractCheckLabelCell

- (void)setContractModel:(SISSContractModel *)contractModel {
    [super setContractModel:contractModel];
    
    self.checkOneButton.selected = contractModel.isChecked;
    self.checkTwoButton.selected = contractModel.isCheckedTwo;
    self.checkThreeButton.selected = contractModel.isCheckedThree;
    self.onelabel.text = contractModel.rightStr;
    self.twolabel.text = contractModel.rightTwoStr;
    self.threelabel.text = contractModel.rightThreeStr;
    
}



#pragma mark - 点击事件
- (void)checkButtonClickAction:(UIButton *)button {
    
    self.checkedButton.selected = NO;
    self.checkedButton = button;
    self.checkedButton.selected = !button.selected;
    
    if (button.tag == 100) {
        self.checkOneButton.selected = YES;
        self.checkTwoButton.selected = NO;
        self.checkThreeButton.selected = NO;
        self.contractModel.isCheckedTwo = NO;
        self.contractModel.isCheckedThree = NO;
        self.contractModel.isChecked = button.isSelected;
    } else if (button.tag == 101) {
        self.checkOneButton.selected = NO;
        self.checkTwoButton.selected = YES;
        self.checkThreeButton.selected = NO;
        self.contractModel.isChecked = NO;
        self.contractModel.isCheckedTwo = button.isSelected;
        self.contractModel.isCheckedThree = NO;
    } else {
        self.checkOneButton.selected = NO;
        self.checkTwoButton.selected = NO;
        self.checkThreeButton.selected = YES;
        self.contractModel.isChecked = NO;
        self.contractModel.isCheckedTwo = NO;
        self.contractModel.isCheckedThree = button.isSelected;
    }
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 100;
    [button setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(checkButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:button];
    self.checkOneButton = button;
    
    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    label.textColor = MAIN_TEXT_COLOR;
    label.text = @" ";
    label.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:label];
    self.onelabel = label;
    
    UIButton *checkTwoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [checkTwoButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [checkTwoButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [checkTwoButton addTarget:self action:@selector(checkButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    checkTwoButton.tag = 101;
    [self.contentView addSubview:checkTwoButton];
    self.checkTwoButton = checkTwoButton;
    
    UILabel *twolabel = [[UILabel alloc] init];
    twolabel.numberOfLines = 0;
    twolabel.textColor = MAIN_TEXT_COLOR;
    twolabel.text = @" ";
    twolabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:twolabel];
    self.twolabel = twolabel;
    
    UIButton *checkThreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [checkThreeButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [checkThreeButton setImage:[UIImage imageNamed:@"mainCheckSelected"] forState:UIControlStateSelected];
    [checkThreeButton addTarget:self action:@selector(checkButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    checkThreeButton.tag = 102;
    [self.contentView addSubview:checkThreeButton];
    self.checkThreeButton = checkThreeButton;
    
    UILabel *threelabel = [[UILabel alloc] init];
    threelabel.numberOfLines = 0;
    threelabel.textColor = MAIN_TEXT_COLOR;
    threelabel.text = @" ";
    threelabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:threelabel];
    self.threelabel = threelabel;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    CGSize buttonSize = CGSizeMake(24, 24);
    [self.checkOneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.contentView).offset(1.5 * margin);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.onelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.checkOneButton.mas_right);
        make.top.equalTo(weakSelf.checkOneButton);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.checkTwoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.checkOneButton);
        make.top.equalTo(weakSelf.onelabel.mas_bottom).offset(2 * margin);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.twolabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.checkTwoButton.mas_right);
        make.top.equalTo(weakSelf.checkTwoButton);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.checkThreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.checkTwoButton);
        make.top.equalTo(weakSelf.twolabel.mas_bottom).offset(2 * margin);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.threelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.checkThreeButton.mas_right);
        make.top.equalTo(weakSelf.checkThreeButton);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.threelabel.mas_bottom).offset(1.5 * margin);
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}


@end
